package com.jeeplus.test.jlnu.fieldConfig.controller;

import com.jeeplus.test.jlnu.fieldConfig.domain.FieldConfigEntity;
import com.jeeplus.test.jlnu.fieldConfig.service.ArchivalFieldConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/archivalField")
public class ArchivalFieldConfigController {

    @Autowired
    private ArchivalFieldConfigService archivalFieldConfigService;

    // 获取所有字段配置
    @GetMapping
    public ResponseEntity<List<FieldConfigEntity>> getAllFieldConfigs() {
        List<FieldConfigEntity> configs = archivalFieldConfigService.getAllFieldConfigs();
        return ResponseEntity.ok(configs);
    }

    // 更新字段配置
    @PostMapping("/update")
    public ResponseEntity<String> updateFieldConfig(@RequestBody Map<String, String> config) {
        String fieldKey = config.get("fieldKey");
        String fieldName = config.get("fieldName");
        archivalFieldConfigService.updateFieldConfig(fieldKey, fieldName);
        return ResponseEntity.ok("Field configuration updated successfully.");
    }

}
